/**
 * @author shahma
 */
dojo.provide("medryx.util.tests.TestCaseTest");
dojo.require("doh.TestCase");
dojo.require("doh.runner");

doh.register("medryx.util.tests.TestCaseTest", [
    function testAssertContainsKey(){
		var TestCase = new doh.TestCase("mock", function(){
            var props = {id:null, test:true};
			assertContainsKey(props, "id");
			
		});
	},
	function testAssertionsMadeLocalAndWork() {
		var TestCase = new doh.TestCase("mock", function(){
			console.debug("mock", this);
			try {
				assertTrue(false, "expected error, please ignore.");
			}  catch(e) {
				
			}
			assertFalse(false);
			assertNull(null);
			assertUndefined(a);
			var a = 1;
			assertDefined(a);
			assertNotNull(a);
			
		})
		TestCase.setUp();
		TestCase.runTest();
		TestCase.tearDown();
	},
	function testScaffold() {
		var scaffold = {
			setUp:function() {
				console.debug("in setup");
				this.inSetup = true;
			},
			runTest:function() {
				console.debug("in runTest");
			}
			
		};
		var TestCase = new doh.AsyncTestCase("test", function() {
		}, scaffold);
		doh.assertTrue(scaffold.setUp == TestCase.setUp);
		doh.assertFalse(TestCase.inSetup);
		TestCase.setUp();
		doh.assertTrue(TestCase.inSetup);
	},
	function testAsyncTestCase(){
		
		var scaffold = {
			setUp:function() {
				console.debug("in setup");
				this.deferred = new dojo.Deferred();
				this.inSetup = true;
			}
			
		};
		var TestCase = new doh.AsyncTestCase("test", function() {
			console.debug("in Builder", this);
			this.inBuilder = true;
			deferred.callback([100, "ABC"]);
			return deferred;
		}, function(result) {
			console.debug("in tester:", result);
			doh.assertEqual([100, "ABC"], result);
			this.inTester = true;
			return result;
		}, scaffold);
		
		TestCase.setUp();
		TestCase.runTest();
		
		var dohDef = new doh.Deferred();
		TestCase.deferred.addCallback(dohDef.getTestCallback(function() {
			console.debug("inSetup: " + TestCase.inSetup);
			doh.assertTrue(TestCase.inSetup);
			console.debug("inBuilder: " + TestCase.inBuilder);
			doh.assertTrue(TestCase.inBuilder);
			console.debug("inTester: " + TestCase.inTester);
			doh.assertTrue(TestCase.inTester);
		}));
		
		return dohDef;
		
	},
	function testAsyncTestCaseWithCallback(){
		
		var scaffold = {
			setUp:function() {
				console.debug("in setup");
				this.deferred = new dojo.Deferred();
				this.inSetup = true;
			}
		};
		var TestCase = new doh.AsyncTestCase("test", function() {
			console.debug("in Builder", this);
			this.inBuilder = true;
			deferred.callback([100, "ABC"]);
			deferred.addCallback(callback);
			//return deferred;
		}, function(result) {
			console.debug("in tester:", result);
			doh.assertEqual([100, "ABC"], result);
			this.inTester = true;
			return result;
		}, scaffold);
		
		TestCase.setUp();
		TestCase.runTest();
		
		var dohDef = new doh.Deferred();
		TestCase.deferred.addCallback(dohDef.getTestCallback(function() {
			console.debug("inSetup: " + TestCase.inSetup);
			doh.assertTrue(TestCase.inSetup);
			console.debug("inBuilder: " + TestCase.inBuilder);
			doh.assertTrue(TestCase.inBuilder);
			console.debug("inTester: " + TestCase.inTester);
			doh.assertTrue(TestCase.inTester);
		}));
		
		return dohDef;
		
	}
	
	
]);
